<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        img {
            max-width: 100%;
            width: auto;
            height: auto;
        }
    </style>
    <title>测试</title>
</head>
<body style="width: 100%;height: 100%;padding: 0px">
<div id="div_box"></div>
<button class="btn" onclick="sendLogon()"> 请求</button>
<button style="height: 40px" onclick="callAppName()"> 调用原生类方法</button>
<button style="height: 40px" onclick="callUserId()">调用原生获取USERID</button>
</body>

<style type="text/css">
    .btn {
        width: 50px;
        height: 40px
    }
</style>

<script type="text/javascript">
    //如果有返回值（默认string）：
    function getAppName(s) {
        alert(s + "")
    }

    function getString(s) {
        alert(s + "")
    }

    //应用名称
    function callAppName() {
        if (window.android) {
            window.android.callAndroid("com.base.commlibs.utils.AppUtil:getAppName", "call");
        }
    }
    //获取UserId
    function callUserId() {
        var key = "USERID"
        if (window.android) {
            window.android.callAndroid("com.blankj.utilcode.util.SPStaticUtils:getString(" + key + ")", "call");
        }
    }

    //点击登录
    function sendLogon() {
        if (window.android != null) {
            window.android.callAndroid("show", "loading");
            var content = {params: {password: "1", logonWardId: "", userCode: "hs01"}, method: "Logon", version: "3.3"}
            var content = JSON.stringify(content)
            window.android.callAndroid(content, "request");
        } else {
            alert(typeof (window.android));
        }
    }

    //登录 回调---对应请求method
    function Logon(objs, msg) {
        android.callAndroid("", "loading");
        if (objs.status == "0") {
            showElement("Js收到消息-->Logon , name:" + objs.userName.toString() + "  参数2:" + msg);
        } else {
            android.callAndroid("fail:" + objs.msg, "dialog");
        }
    }

    //获取扫码
    function getScanMsg(scanInfo) {
        alert(scanInfo)
        showElement("Js收到消息--> scanInfo:" + scanInfo);
    }

    function showElement(msg) {
        var div = document.getElementById("div_box");  //获取div
        var ele = document.createElement('h6');    //创建h2元素节点
        ele.innerHTML = msg;                //设置h2节点的内容
        div.appendChild(ele);                    //添加子节点ele
    }
</script>


</html>